/**************************************************************************************
*  Component of benchmarking program.
**************************************************************************************
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************************/
public class LoopBenchmarkUnit extends BenchmarkUnit {

    public int dummy;
    public int FIBCOUNT;
    public int sum1;
    public int sum2;
    public int fibs[];

    public LoopBenchmarkUnit() {
        dummy = 12;
        FIBCOUNT = 64;
        fibs = new int[FIBCOUNT];
        name = "Loop";
    }

    public int execute() {

        fibs[0] = 1;
        for (int i1 = 1; i1 < FIBCOUNT; i1++)
            fibs[i1] = fibs[i1 - 1] + i1;

        int k2 = 0;
        int i3 = 0;

        for (int j1 = 0; j1 < FIBCOUNT; j1++) {
            for (int k1 = 1; k1 < FIBCOUNT; k1++) {
                int i2 = FIBCOUNT + dummy;
                k2 += i2;
                i3 += 2;
                if (fibs[k1 - 1] < fibs[k1]) {
                    int j2 = fibs[k1 - 1];
                    fibs[k1 - 1] = fibs[k1];
                    fibs[k1] = j2;
                }
            }
        }
        sum1 = k2;
        sum2 = i3;
        return fibs[0];
    }

}

